package com.cssw.fyzb.busi.api.live;

import com.cssw.fyzb.busi.service.live.AnchorService;
import com.cssw.fyzb.busi.service.live.LiveService;
import com.cssw.fyzb.core.exception.BizException;
import com.cssw.fyzb.core.model.dodb.CmfLiveKickOut;
import com.cssw.fyzb.core.model.dodb.CmfLiveMute;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 禁言
 * @author wondream
 */
@Function(description = "禁言", parameters = {
        @Parameter(name = "liveId", type = Type.String, description = "直播ID", required = true),
        @Parameter(name = "operUserId", type = Type.String, description = "操作人ID", required = true),
        @Parameter(name = "userId", type = Type.String, description = "用户ID", required = true)
})
@Component
public class AddLiveMute implements Action {
    public static final Logger logger = LoggerFactory.getLogger(AddLiveMute.class);

    @Autowired
    LiveService liveService;

    @Override
    public Response execute(Request request) throws Exception {
        try {
            Long liveId = request.getLong("liveId");
            Long operUserId = request.getLong("operUserId");
            Long userId = request.getLong("userId");
            CmfLiveMute cmfLiveMute = liveService.queryLiveMute(liveId, operUserId, userId);
            if (cmfLiveMute != null) {
                return Response.fail("请勿重复操作");
            }
            liveService.addLiveMute(liveId, operUserId, userId);
            return Response.success("操作成功");
        } catch (Exception e){
            if (e instanceof BizException) {
                BizException be = (BizException) e;
                return Response.fail(be.getErrMsg(), be.getErrCode());
            }
            logger.error("", e);
            return Response.fail("操作失败");
        }
    }
}
